from django.conf.urls.defaults import url

def static_url(path, file, document_root='static'):
    return url('^%s$' % path,
               'django.views.static.serve',
               dict(path=file, document_root=document_root))

def make_url(parts):
    '''Makes a URL by joining the parts. Prepends and appends slashes.

    >>> make_url(['a','b','c'])
    '/a/b/c/'
    '''
    return '/'.join(['']+map(str,parts)+[''])

def _method_not_allowed_returner(*a, **kw):
    from django.http import HttpResponse
    return HttpResponse('Method not allowed', status=405)

import new
def method_dispatcher(name):
    def dispatcher(self, request, *a, **kw):
        m = name + '_' + request.method
        return getattr(self, m, _method_not_allowed_returner)(request, *a, **kw)
    dispatcher.__name__ = name
    return dispatcher

class instance_decorator(object):
    def __init__(self, *decorators):
        self._decorators = decorators

    def __get__(self, instance, owner):
        f = new.instancemethod(self.f, instance, owner)
        for dec in self._decorators:
            f = dec(f)
        return f

    def __call__(self, f):
        self.f = f
        return self
